﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using MobileWeb.Models;

namespace MobileWeb.Helpers
{
    public class SearchHelper
    {
        public static List<ApartmentBasic> GetApartments(string areaId, string floorId)
        {
            var xmlContent = XmlHelper.GetXmlContent(String.Format("http://www.ban-centar.hr/xml/search/{0}/{1}", floorId, areaId));

            var elementList = xmlContent.Elements();
            var apartments = new List<ApartmentBasic>();
            foreach (var item in elementList)
            {
                var apartment = new ApartmentBasic()
                {
                    Area = Double.Parse(item.Element("area").Value, CultureInfo.CurrentCulture),
                    Floor = item.Element("floor").Value,
                    Code = item.Element("code").Value
                };
                apartments.Add(apartment);
            }

            return apartments;
        }
    }
}